package sql

import (
	"gitee.com/lstack_light/light-utils/middleware/sql/common"
	"gitee.com/lstack_light/light-utils/middleware/sql/mongo"
	"gitee.com/lstack_light/light-utils/middleware/sql/mysql"
)

type Client interface {
	Exit() error
	Migrate(tables ...interface{}) error
	Insert(data ...interface{}) error
	Delete(table interface{}, query map[string]interface{}) error
	Update(table interface{}, query map[string]interface{}, updates map[string]interface{}) error
	SelectOne(table interface{}, result interface{}, query map[string]interface{}) error
	SelectMany(table interface{}, result interface{}, query map[string]interface{}) error
	CustomQuery(result interface{}, sql string, values ...interface{}) error
}

type DbClient struct {
	Type        common.DbType
	MysqlConfig *mysql.DbConfig
	MongoConfig *mongo.DbConfig
}

type Native struct {
	Type        common.DbType
	MysqlClient mysql.Native
	MongoClient mongo.Native
}

func CreateDataBaseClient(dbClient DbClient) (Client, Native, error) {
	native := Native{}
	switch dbClient.Type {
	case common.Mysql:
		client, custom, err := mysql.NewMysqlClient(dbClient.MysqlConfig)
		if nil != err {
			return nil, native, err
		}
		native.MysqlClient = custom
		native.Type = native.MysqlClient.GetType()
		return client, native, nil
	case common.Mongo:
		return nil, native, nil
	default:
		return nil, native, nil
	}
}
